import request from '@/utils/request'
import axios from 'axios'
import Settings from '@/settings'

const URL_PREFIX = '/web/auth'

// 登录方法
const login = (data) => {
  return request({
    url: `${URL_PREFIX}/mock-login`,
    method: 'post',
    data:data
  })
}


const createDebugToken = (userCode) => {
  if (!Settings.debug) {
    return new Promise((resolve, reject) => {
      reject('系统不允许DEBUG')
    })
  }

  const data = new FormData()
  data.append('userCode', userCode)
  return axios.post(
    `${Settings.context}/auth/create-debug`,
    data
  )
}

// 获取用户信息
const getInfo = () => {
  return request({
    url: `${URL_PREFIX}/my-info`,
    method: 'post',
    data: {}
  })
}

// 获取用户的菜单信息
const getMenus = () => {
  return request({
    url: `${URL_PREFIX}/my-menus`,
    method: 'post',
    data: {}
  })
}

// 退出登录
const logout = () => {
  return request({
    url: `${URL_PREFIX}/logout`,
    method: 'post'
  })
}

export default {
  login,
  getInfo,
  getMenus,
  logout,
  createDebugToken
}
